﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IndexConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DemoGetSet demo = new DemoGetSet() { };
            demo.Name = "ss!";
            demo.UserId = demo.Name;
            Console.WriteLine(demo["UserId"]);
            Console.ReadLine();
        }

    }

    public class DemoGetSet
    {
        private readonly Dictionary<string, string> _dic = new Dictionary<string, string>() { };
        /// <summary>
        /// 获取名字
        /// </summary>
        public string Name
        {
            get
            {
                return this["Name"];
            }
            set
            {
                this["Name"] = value;
            }
        }
        /// <summary>
        /// 定义索引器
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public string this[string index]
        {

            get { return _dic[index]; }

            set { _dic.Add(index, value); }

        }
        /// <summary>
        ///  获取用户Id
        /// </summary>
        public string UserId
        {
            get
            {
                return this["UserId"];
            }
            set
            {
                this["UserId"] = value;
            }
        }
    }
}
